package com.hushao.lims.weblims.service.impl;

import com.hushao.lims.weblims.domain.ConsumableInfo;
import com.hushao.lims.weblims.domain.ConsumableRepertory;
import com.hushao.lims.weblims.repository.ConsumableRepertoryRepository;
import com.hushao.lims.weblims.service.ConsumableRepertoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author 930588706
 * @date 18/1/22
 * 耗材库存
 */
@Service
public class ConsumableRepertoryServiceImpl implements ConsumableRepertoryService {
    @Autowired
    private ConsumableRepertoryRepository consumableRepertoryRepository;

    private final int count=0;
    @Override
    public Page<ConsumableRepertory> listConsumableByName(String consumableName, Pageable pageable) {
        consumableName="%"+consumableName+"%";
        return consumableRepertoryRepository.findByConsumableCountGreaterThanAndConsumableInfo_ConsumableNameLike(count,consumableName,pageable);
    }

    @Override
    public ConsumableRepertory findByConsumable(ConsumableInfo consumableInfo) {
        return consumableRepertoryRepository.findByConsumableInfo(consumableInfo);
    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public ConsumableRepertory saveOrUpdate(ConsumableRepertory consumableRepertory) throws Exception {
        return consumableRepertoryRepository.save(consumableRepertory);
    }
}
